package com.zpark.servlet_session;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @PackageName: com.zpark.servlet_session
 * @ClassName: ServletSessionDemo01
 * @Description:
 * @author: RZS
 * @date: 2023/3/10  16:04
 */
@WebServlet("/ss01.do")
public class ServletSessionDemo01 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取session
        HttpSession session = request.getSession();
        // HttpSession session1 = request.getSession(true);
        System.out.println("返回创建 Session 的时间: " + session.getCreationTime());
        System.out.println("返回获取 Seesion 的唯一的 ID: " + session.getId());
        System.out.println("返回客户端上一次发送与此 Session 关联的请求的时间: " + session.getLastAccessedTime());
        System.out.println("返回在无任何操作的情况下，Session 失效的时间，以秒为单位: " + session.getMaxInactiveInterval());
        System.out.println("返回 Session 所属的 ServletContext 对象: " + session.getServletContext());
    }
}
